<?php
namespace Core\Service;

use Phalcon\Di\Injectable;
use Phalcon\Logger\Adapter\File;
use Phalcon\Logger\Formatter\Line as FormatterLine;

class Logger extends Injectable {

    public function register() {
        $path = $this->dir->var('logger');
        if(!is_dir($path)) {
            @mkdir($path, 0777);
        }
        $config = $this->config->get('logger');
        $formatter = new FormatterLine($config->format);
        $this->di->set('logger', function ($file = 'main', $format = null) use($path, $formatter) {
            $logger = new File($path . DIRECTORY_SEPARATOR . "{$file}.log");
            $logger->setFormatter($formatter);
            return $logger;
        }, false);
    }

}